import { useEffect, useState } from 'react';
import { isArray } from 'esy-ui';
import { Swiper } from '@/components';
import { postBanner } from '@/services';

const url = 'https://g1.torry.vip/web/mobile/backend-image/rotate/zh-cn/preset_phone.jpg';

const banners = [{ url }, { url }, { url }];

function Banner() {
  const [list, setList] = useState([]);

  useEffect(() => {
    postBanner({})
      .then((res: any) => {
        if (isArray(res.Data)) {
          setList(res.Data);
        } else {
          throw new Error('error');
        }
      })
      .catch(() => {
        setList(banners);
      });
  }, []);

  return (
    <div className='w-full h-36'>
      <Swiper boxClassName='h-36' list={list} />
    </div>
  );
}

export default Banner;
